<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
        #allMap {width: 1650px;height: 675px;overflow: hidden;margin:0;font-family:"微软雅黑";}
    </style>


    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">

</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>地址管理
            <small>公司分布图</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>地址管理</el-breadcrumb-item>
            <el-breadcrumb-item>公司分布图</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <!--<el-tabs v-model="activeName" @tab-click="handleClick">-->
            <el-tabs v-model="activeName">
                <el-tab-pane label="分布图" name="first">

                    <div id="allMap"></div>

                </el-tab-pane>

                <el-tab-pane label="详细信息" name="second">

                    <div class="filter-container">
                        <el-input placeholder="公司地址" v-model="pagination.queryString" style="width: 200px;"
                                  class="filter-item"></el-input>
                        <el-button @click="findPage()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                    </div>
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>

                        <el-table-column prop="location" label="公司地址" align="center"></el-table-column>
                        <el-table-column prop="longitude" label="所在经度" align="center"></el-table-column>
                        <el-table-column prop="latitude" label="所在纬度" align="center"></el-table-column>

                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>

                    <div class="pagination-container">
                        <el-pagination
                                class="pagiantion"
                                @current-change="handleCurrentChange"
                                :current-page="pagination.currentPage"
                                :page-size="pagination.pageSize"
                                layout="total, prev, pager, next, jumper"
                                :total="pagination.total">
                        </el-pagination>
                    </div>

                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增地址" :visible.sync="dialogFormVisible">
                            <template>
                                <iframe name="right" class="el-main" src="baidu.html" width="100%" height="380px" frameborder="0"></iframe>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>

                </el-tab-pane>
            </el-tabs>

        </div>
    </div>

</div>

</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=ZZWUwUVSPMeNcPrZNpX1oTC0Vsh48rCg"></script>



<script>

    var mapPoints = [];
    var vue = new Vue({
        el: '#app',
        data: {

            activeName: 'first',
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            tableData: []/*{id:1,name:"zhangsan",age:"10",remark:"1"},
                            {id:2,name:"lisi",age:"20",remark:"2"},
                            {id:3,name:"wangwu",age:"30",remark:"3"}*/
            ,//新增表单中对应的套餐数据

            dialogFormVisible: false,//增加表单是否可见
            rules: {//校验规则
                phoneNumber: [{required: true, message: '手机号为必填项', trigger: 'blur'}],
                name: [{required: true, message: '姓名为必填项', trigger: 'blur'}],
                orderDate: [{required: true, message: '预约日期为必填项', trigger: 'blur'}]
            }

        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();//VUE对象初始化完成后调用分页查询方法，完成分页查询
        },
        methods: {

            //handleClick(){},         //切换标签页触发的函数
            //添加
            handleAdd() {
                // alert(frames[0].myValue);
                // alert(frames[0].pp.lng + "," + frames[0].pp.lat);
                var param = {
                    location:frames[0].myValue,
                    longitude:frames[0].pp.lng,
                    latitude: frames[0].pp.lat
                };
                axios.post("/address/add.do",param).then((resp)=>{
                    if (resp.data.flag) {
                        this.$message.success(resp.data.message);
                    }else
                        this.$message.error(resp.data.message);
                }).catch((error)=>{
                    console.log(error);
                }).finally(()=>{
                    //关闭新增窗口
                    this.dialogFormVisible = false;
                    this.findPage();
                })
            },
            //分页查询
            findPage() {
                //发送ajax请求，提交分页相关请求参数（页码、每页显示记录数、查询条件）
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };
                axios.post("/address/findPage.do", param).then((res) => {
                    //解析Controller响应回的数据，为模型数据赋值
                    this.pagination.total = res.data.total;
                    this.dataList = res.data.rows;
                    for (var i = 0; i < this.dataList.length; i++) {
                        var lng = this.dataList[i].longitude;
                        var lat = this.dataList[i].latitude;
                        var location = this.dataList[i].location;

                        var marker = new BMap.Marker(new BMap.Point(lng,lat));
                        map.addOverlay(marker);
                        var label = new BMap.Label(location,{offset:new BMap.Size(20,-10)});
                        marker.setLabel(label);
                        //addClickHandler(location,marker);
                    }
                });

            },
            // 重置表单
            resetForm() {
                this.formData = {};   //重置数据
                this.activeName = 'second';

            },
            // 弹出添加窗口
            handleCreate() {
                //弹出新增窗口
                this.dialogFormVisible = true;
                this.resetForm();
            },

            //切换页码
            handleCurrentChange(currentPage) {
                //设置最新的页码
                this.pagination.currentPage = currentPage;
                //重新调用findPage方法进行分页查询
                this.findPage();
            },

            showMessage(r) {
                if (r == 'Error: Request failed with status code 403') {
                    //权限不足
                    this.$message.error('无访问权限');
                    return;
                } else {
                    this.$message.error('未知错误');
                    return;
                }
            },
            //删除地址
            handleDelete(row) {
                this.$confirm("你确定要删除当前地址吗？", "提示", {
                    type: 'warning'
                }).then(() => {
                    //用户点击确定按钮，发送ajax请求，将预约ID提交到Controller进行处理
                    axios.post("/address/delete.do", row).then((res) => {
                        if (res.data.flag) {
                            //执行成功
                            //弹出成功提示信息
                            this.$message({
                                type: 'success',
                                message: res.data.message
                            });
                            //重新进行分页查询
                            this.findPage();
                        } else {
                            //执行失败
                            this.$message.error(res.data.message);
                        }
                    }).catch((r) => {
                        this.showMessage(r);
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '操作已取消'
                    });
                });
            }
        }
    })
</script>

<script>

    // 百度地图API功能
    //{minZoom:12,maxZoom:18}
    var map = new BMap.Map("allMap");    // 创建Map实例
    var point = new BMap.Point(114.32291785, 30.53645964);
    map.centerAndZoom(point,12);  // 初始化地图,设置中心点坐标和地图级别
    //添加地图类型控件
    map.addControl(new BMap.MapTypeControl({
        mapTypes:[
            BMAP_NORMAL_MAP,
            BMAP_HYBRID_MAP
        ]}));

    map.setCurrentCity("武汉");          // 设置地图显示的城市 此项是必须设置的
    map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放

</script>


</html>